﻿<local:BaseWindow x:Class="PDFRider.WndMergeDocuments"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:PDFRider"
    xmlns:ltl="clr-namespace:LocTranslate;assembly=LocTranslateLibrary"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
    Title="{ltl:Translate loc_wndMergeDocumentsTitle}" Height="400" MinHeight="400" Width="Auto" MinWidth="680"
    WindowStartupLocation="CenterScreen" Style="{StaticResource GenericStyle}" 
    Icon="/PDFRider;component/PDFRider.ico" ResizeMode="CanResize" SizeToContent="Width">
    <Window.Resources>
        <local:EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" MinHeight="55" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1.5*" MinWidth="200" />
            <ColumnDefinition Width="*" MinWidth="200" />
        </Grid.ColumnDefinitions>
        
        <ListView Grid.Row="0" ItemsSource="{Binding Files}" MinWidth="100" Width="Auto" AllowDrop="True"
                  SelectedItem="{Binding SelectedFile}"
                  SelectionMode="Single">
            
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Drop">
                    <cmd:EventToCommand Command="{Binding CmdDropFiles}" PassEventArgsToCommand="True" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="{ltl:Translate loc_fileColumn}" Width="300" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="..\images\pdf.png" Style="{StaticResource SmallImage}"
                                           Margin="0,0,3,0" />
                                    <TextBlock Text="{Binding FileName}" />
                                    <!-- Maybe I could handle MoveUp and MoveDown this way... -->
                                    <!--<Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:BaseWindow}}, 
                                        Path=DataContext.CmdMoveUp}"
                                            CommandParameter="{Binding .}">
                                    </Button>-->
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{ltl:Translate loc_pagesColumn}" Width="90">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Interval}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsValidInterval}" Value="False">
                            <Setter Property="Foreground" Value="DarkRed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
        
        <WrapPanel Grid.Row="1" Orientation="Horizontal" Margin="5" >
            <Button Command="{Binding CmdMoveUp}"
                    Style="{StaticResource StandardRectangleDialogButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="..\images\up.png" Style="{StaticResource SmallImage}" />
                    <TextBlock Text="{ltl:Translate loc_moveUp}" />
                </StackPanel>
            </Button>
            <Button Command="{Binding CmdMoveDown}"
                    Style="{StaticResource StandardRectangleDialogButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="..\images\down.png" Style="{StaticResource SmallImage}" />
                    <TextBlock Text="{ltl:Translate loc_moveDown}" />
                </StackPanel>
            </Button>
            <Button Command="{Binding CmdAddFile}"
                    Style="{StaticResource StandardRectangleDialogButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="..\images\edit_add.png" Style="{StaticResource SmallImage}" />
                    <TextBlock Text="{ltl:Translate loc_addFile}" />
                </StackPanel>
            </Button>
            <Button Command="{Binding CmdRemoveFile}"
                    Style="{StaticResource StandardRectangleDialogButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="..\images\edit_remove.png" Style="{StaticResource SmallImage}" />
                    <TextBlock Text="{ltl:Translate loc_removeFile}" />
                </StackPanel>
            </Button>
        </WrapPanel>
        
        <TextBlock Grid.Row="2" Style="{StaticResource InformationTextBlock}" Text="{Binding Information}" />
        
        <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ProgressBar Margin="7" IsTabStop="False" Value="{Binding MergeProgress}" Maximum="{Binding MergeProgressMax}"
                         Visibility="{Binding Path=MergeStarted, Converter={StaticResource BooleanToVisibilityConverter}}" />

            <Button Grid.Column="1" Content="{ltl:Translate loc_btnOK}" Command="{Binding CmdMerge}"
                Style="{StaticResource StandardRectangleDialogButton}" />
            <Button Grid.Column="2" Content="{ltl:Translate loc_btnCancel}" Command="{Binding CmdClose}"
                Style="{StaticResource StandardRectangleDialogButton}" />
            
        </Grid>
        
        
        <DockPanel Grid.Column="1" Grid.RowSpan="4" Margin="2" MinWidth="100" LastChildFill="True">
            <WrapPanel Orientation="Horizontal" DockPanel.Dock="Top">
                <RadioButton Margin="2" Content="{ltl:Translate loc_rdbAllPages}" VerticalAlignment="Center"
                         IsChecked="{Binding Path=SelectedFile.PagesInterval, Converter={StaticResource enumBooleanConverter}, 
                ConverterParameter=AllPages, Mode=TwoWay}" GroupName="1" Name="rdbAll" />
                <RadioButton Margin="2" Content="{ltl:Translate loc_rdbPagesInterval}" VerticalAlignment="Center"
                         IsChecked="{Binding Path=SelectedFile.PagesInterval, Converter={StaticResource enumBooleanConverter}, 
                ConverterParameter=Interval, Mode=TwoWay}" GroupName="2" Name="rdbInterval" />
                <local:IntervalTextBox Width="100"
                         IsValidInterval="{Binding SelectedFile.IsValidInterval}"
                         Text="{Binding Path=SelectedFile.Interval, UpdateSourceTrigger=PropertyChanged}"
                         IsEnabled="{Binding ElementName=rdbInterval, Path=IsChecked}" ToolTip="{ltl:Translate loc_pagesIntervalInfo}">
                    <local:IntervalTextBox.Style>
                        <Style TargetType="{x:Type local:IntervalTextBox}" BasedOn="{StaticResource IntervalTextBox}">
                            <Style.Triggers>
                                <Trigger Property="IsEnabled" Value="True">
                                    <Setter Property="local:FocusExtension.IsFocused" Value="True" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </local:IntervalTextBox.Style>
                </local:IntervalTextBox>
            </WrapPanel>
            <Border BorderBrush="DarkSlateGray" BorderThickness="2">
                <WebBrowser local:WebBrowserUtility.BindableSource="{Binding SelectedFile.Uri, Mode=OneWay}" />
            </Border>
        </DockPanel>
        
        <GridSplitter Grid.Column="1" Grid.RowSpan="4" HorizontalAlignment="Left" VerticalAlignment="Stretch"
                      Width="2" />
        
    </Grid>
</local:BaseWindow>
